<extend name='Public/demo' />

<block name='contents'>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Confirm/jquery-confirm.css" />
<script type="text/javascript" src="__PUBLIC__/Confirm/jquery-confirm.js"></script>
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              前台皮肤管理
                          </header>
                          <table class="table table-striped table-advance table-hover">
                              <thead>
                              <tr>
                                  <th><i class="icon-bullhorn"></i> 文件类型</th>
                                  <th class="hidden-phone"><i class="icon-question-sign"></i> 文件名称</th>
                                  <th><i class="icon-bookmark"></i> 文件格式</th>
                                  <th><i class=" icon-edit"></i> 修改时间</th>
                                  <th>操作</th>
                              </tr>
                              </thead>
                              <tbody>
                                      <foreach name="listdir" item="val" >
                                            <tr>
                                                <td><a href="#"><?php echo is_dir($val) ? '目录' : '&nbsp;&nbsp;|______文件' ;  ?></a></td>
                                                <td class="hidden-phone"><?php echo basename($val) ?></td>
                                                <td><?php echo pathinfo($val)['extension'] ; ?></td>
                                                <td><span class="label label-success label-mini"><?php echo date('Y-m-d H:i:s' , filemtime($val)) ?></span></td>
                                                <td>
                                                      <?php if( is_dir($val) ){?>
                                                                <button class="dirfilebtn btn btn-success btn-xs" data-type="dir" data-path="<?php echo $key ?>"><i class="icon-plus"></i> 添加文件</button>
                                                      <?php }else{?>
                                                                <button class="dirfilebtn btn btn-primary btn-xs" data-type="fileedit" data-path="<?php echo $key ?>"><i class="icon-pencil"></i> 编辑文件</button>
                                                                <button class="dirfilebtn btn btn-danger btn-xs" data-type="filedel" data-path="<?php echo $key ?>"><i class="icon-trash "></i> 删除文件</button>
                                                      <?php }?>
                                                </td>
                                            </tr>
                                      </foreach>
                              </tbody>
                          </table>
                      </section>
                  </div>
              </div>
              <script type="text/javascript">
                //添加文件的文件名
                var arr = new Array();
                //计数用
                var num = 0;
                //得到data-type
                var type = '';
                var pathurl = '';
                $('.dirfilebtn').live('click',function(){
                    //得到data-type
                    type =  $(this).attr('data-type');
                    //得到当前的元素对象
                    var th = $(this);
                    //得到神秘的代码
                    pathurl =  $(this).attr('data-path');
                    if (type == 'dir') {
                      $.confirm({
                          keyboardEnabled: true,
                          content: '请输入要创建的文件名:<input type="text" class="form-control textareas" placeholder="请输入要创建的文件名!"/>',
                          cancel: function () {
                              $.alert('确认取消添加文件?');
                          },
                          confirm: function () {
                              $.alert('确认添加文件?');
                          }
                      });
                    }else if(type == 'fileedit'){
                      location.href = "{:U('Theme/edit')}?pathurl="+pathurl;
                    }else if(type == 'filedel'){
                        //发送ajax
                        var res = confirm('你确定要删除这个文件吗?')
                        if (res) {
                          $.post("{:U('Theme/remove')}",{'pathurl':pathurl},function(data){
                            th.parents('tr').remove();
                          })
                        }
                    }
                });
                $('.buttons').find('button:eq(0)').live('click',function(){
                      arr[num] = $('.textareas').val() ;
                      num++;
                      if (num ==2) {
                        //发送ajax
                        $.post("{:U('Theme/touch')}",{'filename':arr[0],'pathurl':pathurl},function(data){
                          console.log(data);
                          location.href =  location.href;
                          arr = new Array();
                          num = 0;
                        })
                      }
                })
              </script>
</block>
